package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.result.FilterResult;
import cn.itcast.hotel.pojo.result.PageResult;
import cn.itcast.hotel.pojo.vo.RequestParams;
import cn.itcast.hotel.pojo.vo.RequestTermParams;
import cn.itcast.hotel.service.impl.HotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/hotel")
public class HotelController {


    @Autowired
    private HotelService hotelService;

    /**
     * 搜索查询(分页条件查询)
     * @param requestParams
     * @return
     * @throws IOException
     */
    @PostMapping("/list")
    public PageResult searchPageInfo(@RequestBody RequestTermParams requestParams) throws IOException {
        PageResult result = hotelService.searchPageInfo(requestParams);
        return result;
    }

    /**
     * 过滤查询数据(trem查询)
     */
    @PostMapping("/filters")
    public FilterResult searchPageTrem(@RequestBody RequestTermParams requestTermParams) throws IOException {
        FilterResult filterResult = hotelService.searchFilter(requestTermParams);
        return filterResult;
    }

    /**
     * 拼音补全搜索
     * @param key
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> searchSpell(@RequestParam String key) throws IOException {
        List<String> list = hotelService.searchSpell(key);
        return list;
    }
}
